﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;
public partial class Agency_company_biaoshu_look : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
        if (_Account != null)
        {
            if (int.Parse(_Account.Type) == 17 || int.Parse(_Account.Type) == 1)
            {
                showgrid();
            }
            else
            {
                Response.Write("<script>window.alert('对不起，您无权查看！');</script>");
                Response.Write("<script>window.location.href='../HomePage/Default.aspx';</script>");
            }

        }
        else
        {
            Response.Write("<script>window.alert('对不起，请重新登录！');</script>");
            Response.Write("<script>window.location.href='../HomePage/Default.aspx';</script>");
        }
    }
    protected void showgrid()
    {
        string strConditions;
        strConditions = fctConditions();
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = " company_biaoshu ";                                               //要查询的表明
        //要查询的表明
        dbPage.Key = "id";                                               //表的主键    
        dbPage.Where = strConditions;                                           //查询条件    
        dbPage.SelectField = "usercode_sc,username_sc,usercode_tb,username_tb,add_tjr,add_time";//要显示的字段
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
        dbPage.PageSize = 30;                                                    //没有显示记录条数   
        dbPage.OrderBy = "add_time desc";        //排序字段
        System.Data.IDataReader dr = dbPage.ExecuteReader();
        GridView1.DataSource = dr;
        GridView1.DataBind();
        dr.Close();
        dr.Dispose();
        dbPage.Db.Close();
        db.Close();
        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键

    }
    public string fctConditions()
    {
        string strwhere = "  1=1 ";
        HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
        if (int.Parse(_Account.Type) == 17)
        {
            strwhere += " and add_tjr ='" + _Account.AccountName.ToString() + "'";
        }
        string str_usercode_sc = TextBox1.Text.ToString().Trim();
        string str_username_sc = TextBox2.Text.ToString().Trim();
        string str_usercode_tb = TextBox3.Text.ToString().Trim();
        string str_username_tb = TextBox4.Text.ToString().Trim();
        if (str_usercode_sc != "")
        {
            strwhere += " and  usercode_sc like '%" + str_usercode_sc + "%'";
        }
        if (str_username_sc != "")
        {
            strwhere += " and username_sc like '%" + str_username_sc + "%'";
        }
        if (str_usercode_tb != "")
        {
            strwhere += " and  usercode_tb like '%" + str_usercode_tb + "%'";
        }
        if (str_username_tb != "")
        {
            strwhere += " and username_tb like '%" + str_username_tb + "%'";
        }
        string str_txtjz = txtjz.Text.ToString().Trim();

        if (str_txtjz != "")
        {
            strwhere += " and isnull(add_time,'1900-01-01')>='" + str_txtjz + "' ";
        }
        string str_time = TextBox5.Text.ToString().Trim();

        if (str_time != "")
        {
            strwhere += " and isnull(add_time,'1900-01-01') < '" + str_time + "' ";
        }
      

        return strwhere;


    }
    
}
